/***************************************************************************
* GNU/GPL KumbiaForms - PHP Rapid Develpment Framework
* Window Object Manipulation Base Functions
****************************************************************************
* (c) 2007 Andres Felipe Gutierrez <andresfelipe at vagoogle.net>
****************************************************************************/

$W = function(objectName) {
	return document.frames('openWindow').document.getElementById(objectName)
}


var WINDOW = new Object();

WINDOW.open = function(properties){	
	obj = document.createElement("DIV");
	obj.style.position = "absolute";	
	if(!properties.title) properties.title = ""
	if(!properties.titleBackground) properties.titleBackground = "url("+$Kumbia.path+"img/localnav.gif)";
	if(!properties.background) properties.background = "#FFFFFF";
	if(!properties.width) properties.width = "300";
	if(!properties.top) properties.top = "100px";
	if(!properties.left) properties.left = "300px"	
	if(!properties.border) properties.border = "1px solid black"
	if(!properties.url) properties.url = properties.action
	if(properties.onbeforeclose==undefined) properties.onbeforeclose = function(){ }
	if(properties.onclose==undefined) properties.onclose = function(){ }
	for(x in properties){
	  	eval("obj.style."+x+" = properties."+x)
	}	
	obj.style.display = "none"
	html = "<table cellspacing='0' style='background:"+properties.background+";width:"+
	properties.width+"'><tr><td style='cursor:move;color:#FFFFFF;background:"+properties.titleBackground+"'>"+
	properties.title+"</td></tr>"+
	"<tr><td id='windowData' style='padding:2px'></td></tr></table>";	
	obj.innerHTML = html;
	obj.id = "myWindow"
	document.body.appendChild(obj);	
	new Draggable(obj.id);
	if(properties.onclose) WINDOW.onclose = properties.onclose
	if(properties.onbeforeclose){ WINDOW.onbeforeclose = properties.onbeforeclose }			
	obj.close = function(){
		if(properties.onbeforeclose){
			properties.onbeforeclose.call(this)
		}
		new Effect.Fade("myWindow", { 
			afterfinish: function (){
				document.body.removeChild($("myWindow"))	
			}
		})		
	}
	new AJAX.viewRequest({
		action: properties.url,
		container: "windowData",
		callbacks: {
			complete : function(){
				new Effect.Appear("myWindow");
				//refresh();
			}
		}
	});
};


